package com.bistu.openlab.uofspreadsheet.model;

import java.util.ArrayList;
import java.util.List;

/*
 *@author xiaoguang.gao@oracle.com
 *@version 2013-5-8 
 */
public class ExcelContent {
	private List<ExcelSheet> sheetList = null;
	public ExcelContent(){
		for(int i=0;i<3;i++){
			ExcelSheet sheet = new ExcelSheet();
			sheet.setIdentifier("SHEET_"+(i+1));
			sheet.setName("工作表"+(i+1));
			sheet.setStyleReference("DEFSTYLE");
			this.addSheet(sheet);
		}
	}
	/**
	 * get a sheet by identifier
	 * @param identifier
	 * @return
	 */
	public ExcelSheet getExcelSheetByIdentifier(String identifier){
		if(this.sheetList!=null){
			for(ExcelSheet sheet : this.sheetList){
				if(sheet.getIdentifier().equals(identifier)){
					return sheet;
				}
			}
		}
		return null;
	}
	/**
	 * get a sheet by sheet name
	 * @param name
	 * @return
	 */
	public ExcelSheet getExcelSheetByName(String name){
		if(this.sheetList!=null){
			for(ExcelSheet sheet : this.sheetList){
				if(sheet.getName().equals(name)){
					return sheet;
				}
			}
		}
		return null;
	}
	/**
	 * get a sheet by index
	 * @param index
	 * @return
	 */
	public ExcelSheet getExcelSheetByIndex(int index){
		if(this.sheetList!=null){
			return this.sheetList.get(index);
		}
		return null;
	}
	/**
	 * get the count of sheets
	 * @return
	 */
	public int getExcelSheetCount(){
		if(this.sheetList!=null)
			return this.sheetList.size();
		return 0;
	}
	
	
	public void addSheet(ExcelSheet sheet){
		if(this.sheetList==null)
			this.sheetList = new ArrayList<ExcelSheet>();
		this.sheetList.add(sheet);
	}
	public void removeSheet(ExcelSheet sheet){
		if(this.sheetList!=null){
			this.sheetList.remove(sheet);
			if(this.sheetList.size()<=0)
				this.sheetList = null;
		}
	}
	
	public List<ExcelSheet> getSheetList() {
		return sheetList;
	}
	public void setSheetList(List<ExcelSheet> sheetList) {
		this.sheetList = sheetList;
	}
	
}
